﻿
namespace EasyNet.FastDFS
{
    using System.IO;

    public class DownloadStream : IDownloadCallback
    {
        private long currentBytes = 0;

        public Stream InputStream { get; private set; }


        public DownloadStream(Stream inputStream)
        {
            InputStream = inputStream;
        }

        public int Recieve(long fileSize, byte[] data, int bytes)
        {
            try
            {
                InputStream.Write(data, 0, bytes);
            }
            catch
            {
                return -1;
            }

            currentBytes += bytes;
            if (this.currentBytes == fileSize)
            {
                this.currentBytes = 0;
            }

            return 0;
        }
    }
}
